package com.yoga.admin.api.web;

import com.yoga.admin.api.annotation.LoginUser;
import com.yoga.common.appexception.AppException;
import com.yoga.common.appexception.YogaResult;
import com.yoga.common.bo.CourseBO;
import com.yoga.common.bo.YogaAdminBO;
import com.yoga.common.page.PageBO;
import com.yoga.common.qto.CourseQTO;
import com.yoga.manager.admin.AdminCourseManager;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by hdx on 2020/10/17.
 */
@RestController
@RequestMapping("${basePath}")
public class AdminCourseController {

    @Resource
    private AdminCourseManager courseManager;

    @PostMapping("/course/add")
    public YogaResult<CourseBO> addData(@LoginUser YogaAdminBO adminBO, @RequestBody CourseBO courseBO) throws AppException {
        CourseBO result = courseManager.addData(courseBO);
        return new YogaResult<>(result);
    }

    @PostMapping("/course/update")
    public YogaResult<Boolean> updateData(@LoginUser YogaAdminBO adminBO, @RequestBody CourseBO courseBO) throws AppException {
        Boolean result = courseManager.updateData(courseBO);

        return new YogaResult<>(result);
    }


    @PostMapping("/course/delete")
    public YogaResult<Boolean> deleteData(@LoginUser YogaAdminBO adminBO, Long courseId) throws AppException {
        Boolean result = courseManager.deleteData(courseId);

        return new YogaResult<>(result);
    }

    @PostMapping("/course/findPage")
    public YogaResult<PageBO<CourseBO>> findForPage(@LoginUser YogaAdminBO adminBO, CourseQTO courseQTO) throws AppException {
        PageBO<CourseBO> result = courseManager.findForPage(courseQTO);

        return new YogaResult<>(result);
    }

}
